using System;
using System.Collections.Generic;
using System.Text;
using Entities;
using DAL;
using Utility;

namespace BUS
{
    public class tbDanhMucBUS
    {
        public static void Insert(tbDanhMuc danhmuc)
        {
            tbDanhMucDAL dmDAL = new tbDanhMucDAL();
            dmDAL.Insert(danhmuc);
        }
        public static void Update(tbDanhMuc danhmuc)
        {
            tbDanhMucDAL dmDAl = new tbDanhMucDAL();
            dmDAl.Update(danhmuc);
        }
        public static void Delete(int iD)
        {
            tbDanhMucDAL dmDAl = new tbDanhMucDAL();
            dmDAl.Delete(iD);
        }
        public static tbDanhMucCollection Get(string where, int pageindex, int pagesize, string orderby, string orderdirection, out int total)
        {
            tbDanhMucDAL dmDAL = new tbDanhMucDAL();
            return dmDAL.Get(where, pageindex, pagesize, orderby, orderdirection, out total);
        }
        public static tbDanhMucCollection GetAll()
        {
            int total = 0;
            Criteria cri = new Criteria();
            tbDanhMucDAL dmDAL = new tbDanhMucDAL();
            return dmDAL.Get(cri.Criter, 0, 0, tbDanhMucColumns.MaDM.ToString(), OrderDirection.ASC.ToString(), out total);
        }
        public static tbDanhMuc GetByID(int iD)
        {
            int total = 0;
            Criteria cri = new Criteria();
            cri.add(Condition.AND, tbDanhMucColumns.MaDM.ToString(), Condition.EQUAL, iD);
            tbDanhMucDAL dmDAL = new tbDanhMucDAL();
            tbDanhMucCollection dmCollection = dmDAL.Get(cri.Criter, 0, 0, tbDanhMucColumns.MaDM.ToString(), OrderDirection.ASC.ToString(), out total);
            if (dmCollection.Count > 0)
                return dmCollection[0];
            return null;
        }
        public static tbDanhMucCollection GetLimited(int number)
        {
            int total = 0;
            Criteria cri = new Criteria();
            tbDanhMucDAL dmDAL = new tbDanhMucDAL();
            return dmDAL.Get(cri.Criter, 1, number, tbDanhMucColumns.MaDM.ToString(), OrderDirection.DESC.ToString(), out total);
        }
        public static tbDanhMucCollection GetPromotion(int number)
        {
            int total = 0;
            Criteria cri = new Criteria();
            tbDanhMucDAL dmDAL = new tbDanhMucDAL();
            return dmDAL.Get(cri.Criter, 1, number, tbDanhMucColumns.MaDM.ToString(), OrderDirection.DESC.ToString(), out total);
        }
    }
}